<?php
$code                  = Wo_CustomCode('g');
$error                 = "";

$final_array['HEADER'] = (
    (isset($code[0]) && trim(strlen($code[0])) > 0) ? $code[0] : ''
);

$final_array['FOOTER'] = (
    (isset($code[1]) && trim(strlen($code[1])) > 0) ? $code[1] : ''
);

$final_array['STYLE']  = (
    (isset($code[2]) && trim(strlen($code[2])) > 0) ? $code[2] : ''
);
?>
<div class="container-fluid">
    <div class="block-header">
        <h2>设计 > 自定义 JS / CSS</h2>
    </div>
    <!-- Vertical Layout -->
    <div class="row">
        <div class="col-lg-12 col-md-12">
            <div class="card">
                <div class="header">
                    <h2>自定义 JS / CSS</h2>
                </div>
                <div class="body">
                    <div class="alert alert-success ads-settings-alert"></div>
                    <form class="ads-settings" method="POST">
                        <div class="form-group">
                        	<label class="form-label">页头自定义 JavaScript</small></label>
                            <textarea name="cheader" id="cheader-js" class="form-control"><?php echo $final_array['HEADER']?></textarea>
                        </div>
                       <div class="form-group">
                        	<label class="form-label">页脚自定义 JavaScript</small></label>
                            <textarea name="cfooter" id="fheader-js" class="form-control"><?php echo $final_array['FOOTER']?></textarea>
                        </div>
                        <div class="form-group">
                        	<label class="form-label">页头 CSS Style</small></label>
                            <textarea name="css" id="custom-css" class="form-control"><?php echo $final_array['STYLE']?></textarea>
                        </div>
                        <button type="submit" class="btn btn-primary m-t-15 waves-effect">保存</button>
                    </form>
                </div>
            </div>
        </div>
        <div class="clearfix"></div>
    </div>
    <!-- #END# Vertical Layout -->
<script>
$(function() {
    var form_ads_settings = $('form.ads-settings');
    var readOnlyCodeMirror = CodeMirror.fromTextArea(document.getElementById('cheader-js'), {
         mode: "javascript",
         theme: "default",
         lineNumbers: true,
         readOnly: false
      });

      var readOnlyCodeMirror = CodeMirror.fromTextArea(document.getElementById('fheader-js'), {
         mode: "javascript",
         theme: "default",
         lineNumbers: true,
         readOnly: false
      });

      var readOnlyCodeMirror = CodeMirror.fromTextArea(document.getElementById('custom-css'), {
         mode: "css",
         theme: "default",
         lineNumbers: true,
         readOnly: false
      });   
    form_ads_settings.ajaxForm({
        url: Wo_Ajax_Requests_File() + '?f=admin_setting&s=update_custom_code',
        beforeSend: function() {
            form_ads_settings.find('.waves-effect').text('请稍后..');
        },
        success: function(data) {
        	if (data.status == 200) {
               swal({
                  title: "保存更改!",
                  text: "您的更改已成功保存",
                  type: "success"
               });
	           }
	           else if (data.status == 400) {
	               swal({
	                  title: "Request Error!",
	                  text: "Please check your details!",
	                  type: "error"
	               });
	           }
	           else if (data.status == 500) {
	               swal({
	                  title: "File Permissions Error!",
	                  text: "Can't save changes. themes/{{CONFIG theme}}/custom directory is not writable!",
	                  type: "error"
	               });
	           }
	           setTimeout(function(){
	               swal.close();
	           }, 5000);
	           form_ads_settings.find('.waves-effect').text('保存');
              $("html, body").animate({ scrollTop: 0 }, "slow");
        }
    });
});
</script>